<template>
	<div>
		<Tabs :currentIndex="currentIndex" @onIndex="getIndex">
			<Tab index="1" label="中国疫情地图">
				<div id="chinaMap"></div>
			</Tab>
			<Tab index="2" label="世界疫情地图">
				<div id="worldMap"></div>
			</Tab>
		</Tabs>
	</div>
</template>

<script>
	import api from '../api/index.js'
	export default {
		name: 'Map',
		data() {
			return {
				currentIndex: "1"
			}
		},
		mounted() {
			api.getnationwideData().then(res => {
				console.log(res);
				if (res.status == 200) {
					var allCity = [];
					for (var i = 0; i < res.data.retdata.length; i++) {
						var objexa = {
							name: res.data.retdata[i].xArea,
							value: res.data.retdata[i].curConfirm
						}
						allCity.push(objexa);
					}
					this.$charts.chinaMap("chinaMap", allCity);
				}
			}).catch(error => {
				console.log(error);
			});
			api.getworldData().then(res => {
				console.log(res);
				if (res.status == 200) {
					var allworld = [];
					for (var i = 0; i < res.data.newslist.length; i++) {
						var objexa = {
							name: res.data.newslist[i].provinceName,
							value: res.data.newslist[i].currentConfirmedCount
						}
						allworld.push(objexa);
					}
					this.$charts.worldMap("worldMap", allworld);
				}
			}).catch(error => {
				console.log(error);
			});
		},
		methods: {
			getIndex(index) {
				this.currentIndex = index
			},
			setColor(value) {
				let currentColor = "";
				switch (true) {
					case value == 0:
						currentColor = "#fff";
						break;
					case value > 0 && value < 10:
						currentColor = "#FDFDCF";
						break;
					case value >= 10 && value < 100:
						currentColor = "#FE9E83";
						break;
					case value >= 100 && value < 500:
						currentColor = "#E55A4E";
						break;
					case value >= 500 && value < 10000:
						currentColor = "#4F070D";
						break;
				}
				return currentColor;
			}
		}
	}
</script>

<style scoped>
	#worldMap {
		width: 3.75rem;
		height: 4rem;
		margin: 0rem auto;
	}

	#chinaMap {
		width: 3.75rem;
		height: 4rem;
		margin: 0rem auto;
	}

	.title {
		border-top: 0.005rem solid #ebebeb;
		border-bottom: 0;
		display: -webkit-box;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-align: center;
		-ms-flex-align: center;
		align-items: center;
		-webkit-box-pack: start;
		-ms-flex-pack: start;
		justify-content: flex-start;
		height: 0.44rem;
		padding: 0 0.16rem;
		font-weight: 500;
		font-size: 0.17rem;
		line-height: 0.44rem;
		background: #fff;
	}

	.title::before {
		content: "";
		width: 5px;
		height: 20px;
		background: #4169e2;
		margin-right: 10px;
	}
</style>
